#include "stdafx.h"

#include "util/named.h"

namespace natrium {
	namespace util {
		Named::Named(const std::string& name):
			mName(name)
		{
		}

		Named::Named(std::string&& name):
			mName(name)
		{
		}
	
		Named::~Named() {
		}

		const std::string& Named::getName() const {
			return mName;
		}

		std::map<std::string, UniqueNamed*> UniqueNamed::mNameRegistry;

		UniqueNamed::UniqueNamed(const std::string& name):
			Named(name)
		{
			auto it = mNameRegistry.find(name);
		
			if (it != mNameRegistry.end())
				throw std::runtime_error("Duplicate name entry");

			mNameRegistry.emplace(std::make_pair(name, this));
		}

		UniqueNamed::UniqueNamed(std::string&& name):
			Named(name)
		{
			auto it = mNameRegistry.find(name);
		
			if (it != mNameRegistry.end())
				throw std::runtime_error("Duplicate name entry");

			mNameRegistry.emplace(std::make_pair(name, this));
		}

		UniqueNamed::~UniqueNamed() {
		}
	}
}
